package cn.edu.tust.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.edu.tust.bean.UserInfoBean;
import cn.edu.tust.model.UserInfoModel;
import cn.edu.tust.myUtils.MyUtils;

/**
 * ajax数据查询
 */
@WebServlet("/UserInfoShowDataServlet")
public class UserInfoShowDataServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		// 设置request、response的编码，防止中文乱码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		// 进行ajax响应处理
		// 调用model层进行数据库查询操作
		List<UserInfoBean> lstUserInfo = MyUtils.getNewInstance(UserInfoModel.class).getAllUserInfo();
		// 将查询到的结果集转换为json字符串
		String strResult = JSON.toJSONStringWithDateFormat(lstUserInfo, "yyyy-MM-dd HH:mm:ss");
		// 将查询结果返回给ajax引擎
		PrintWriter pw = response.getWriter();
		// 将返回的内容发送给客户端的ajax引擎
		pw.println(strResult);
	}

}
